const router = require('koa-router')()
const upload=require('../middleware/multer') 
const userController = require('../controllers/userController')
const checkController = require('../controllers/checkTimeController')
const leaveController = require('../controllers/leaveController')
const overtimeController = require('../controllers/overtimeController')
const forgetController = require('../controllers/forgetController')

router.prefix('/user')

router.get('/', function (ctx, next) {
  ctx.body = 'this is a users response!'
})

router.get('/bar', function (ctx, next) {
  ctx.body = 'this is a users/bar response'
})
//新建用户
router.post('/adduser',upload.single('file'),userController.create);
//获取所有用户
router.get('/getalluser',userController.getalluser);
//更新用户信息
router.post('/updateduser',upload.single('file'),userController.updatedUser);
//删除用户信息
router.get('/deleteuser/:id',userController.deleteUserById);
//用户登录
router.post('/login', userController.userlogin);
//用户登录
router.post('/getlast', userController.getlast);
//修改用户密码
router.post('/updatepsw',userController.updatepsw);

//获得用户的打卡记录
router.post('/userchecktime',checkController.getCheckTimeByName);
//上传考勤文件
router.post('/uploadex',upload.single('file'),checkController.uploadex);
//导出考勤记录
router.post('/exportex',checkController.exportex);
//上传请假文件
router.post('/uploadexleave',upload.single('file'),leaveController.uploadex);
//上传加班文件
router.post('/uploadexovertime',upload.single('file'),overtimeController.uploadex);
//上传忘打卡
router.post('/uploadexforget',upload.single('file'),forgetController.uploadex);

// async(ctx,next)=>{
//   console.log("-----------body-----",ctx.request.body);

//   console.log("-----------userName-----",ctx.request.body.username);
//   console.log("-----------nickName-----",ctx.request.body.password);
//   // ctx.body = 'Hello World';
// })
//根据用户名查找用户loginname

// router.post('/upload',upload.single('file'), async (ctx, next) => {
 
//   console.log(ctx.req);
//   ctx.body = {
//     filename: ctx.req.file.filename  //返回文件名 
//   }
// })

module.exports = router
